package com.easy.common.bean;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import com.easy.common.constant.CommonConstant;
import com.easy.common.constant.EnumConfig;

/**
 * 接口返回结果
 * @param <T>
 */
public class Result implements Serializable {

	private static final long serialVersionUID = 8634580794272004072L;
	
	private int status = EnumConfig.S_CODE.OK.getCode();
	private String msg = EnumConfig.S_CODE.OK.getName();
	private Object data;
	private Map<Object, Object> param = null;
	
	public Result() {}
	public Result(Object data) {
		this.data = data;
	}
	public Result(Object data, EnumConfig.S_CODE scode) {
		this.data = data;
		this.status = scode.getCode();
	}
	public Result(Object data, EnumConfig.S_CODE scode, String msg) {
		this.data = data;
		this.status = scode.getCode();
		this.msg = msg;
	}
	public Result(Object data, String msg) {
		this.data = data;
		this.msg = msg;
	}
	public int getStatus() {
		return status;
	}
	public void setStatus(EnumConfig.S_CODE scode) {
		this.status = scode.getCode();
		this.msg = EnumConfig.S_CODE.getEnum(this.status).getName();
	}
	public void setStatus(EnumConfig.S_CODE scode, String msg) {
		this.status = scode.getCode();
		this.msg = msg;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	public Object getData() {
		if (null != this.param) {
			return param;
		}
		return data;
	}
	public void setData(Object data) {
		this.data = data;
	}
	public void setData(Object data, EnumConfig.S_CODE scode) {
		this.data = data;
		this.status = scode.getCode();
	}
	public void setData(EnumConfig.S_CODE scode, String msg) {
		this.status = scode.getCode();
		this.msg = msg;
	}
	public void setData(Object data, String msg) {
		this.data = data;
		this.msg = msg;
	}
	public void setData(Object data, EnumConfig.S_CODE scode, String msg) {
		this.data = data;
		this.status = scode.getCode();
		this.msg = msg;
	}
	public void put(Object key, Object value) {
		if (null == param) {
			param = new HashMap<Object, Object>();
		}
		this.param.put(key, value);
	}
	public String toJson() {
		if (null != this.param) {
			return CommonConstant.gson.toJson(this.param);
		}
		return CommonConstant.gson.toJson(this.data);
	}
	
}
